<?php
//'********************************************************************************
//'Muc dich : Kiem tra xem nguoi dang nhap hien thoi co phai la QUAN TRI cua mot ung dung hay khong
// Tham so:
//   - pApplicationID: ID cua ung dung 
//   - pStaffID: ID cua nguoi dang nhap
// Tra lai: 1-Neu la nguoi QUAN TRI, 0-neu khong phai quan tri
//'********************************************************************************
function user_is_app_admin($pApplicationID, $pStaffID){
	global $conn;
	global $_ISA_DB_TYPE;
	$return_value = false;
	if (_is_sqlserver()){
		$cmd = mssql_init("User_IsAppAdmin", $conn);
		mssql_bind($cmd, "@p_application_id", $pApplicationID, SQLINT4);
		mssql_bind($cmd, "@p_staff_id", $pStaffID, SQLINT4);
		$result = mssql_execute($cmd);
		$rs = @mssql_fetch_array($result);
		if($rs['IS_APP_ADMIN']==1){
			$return_value = true;
		}	
		@mssql_free_result($result);
	}
	return $return_value;
}	
/*Ham thuc hien lay ra "Chuoi" cac don vi muc tren cua can bo hien thoi (duong dan toi staff)
cHI CAN TIM TU THANG UNIT CUOI CUNG*/
function get_string_unit_level_higher($unit_id){
	$v_root_id = 44;//get_root_unit_id();
	echo sizeof($arr_all_unit); exit;
	$v_list_unit_higher = ""; 
	while($unit_id <> $v_root_id){
		for($i = 0; $i < sizeof($arr_all_unit); $i++){
			if ($arr_all_unit[$i][0] == $unit_id){
				$v_list_unit_higher = $v_list_unit_higher.$arr_all_unit[$i][1].",";
				$unit_id =  $arr_all_unit[$i][1];
				break;
			}
		}
	}
	return $v_list_unit_higher;
}
/*
Ham thuc hien lay danh sach cac nhom ma chuc nang thuoc vao cac nhom do.
Luu y: Mang $arr_function_belong_group phai duoc sap xep truoc theo id cua chuc nang
*/
function get_group_list_of_function($p_function_id,$p_arr_function_belong_group){
	$v_found = false;
	$v_count = sizeof($p_arr_function_belong_group);
	$v_group_list = "";
	if ($v_count>0){
		for ($i=0; $i<$v_count; $i++){
			if ($p_arr_function_belong_group[$i][0] == $p_function_id){
				$v_found = true;
				if ($v_group_list == ""){
					$v_group_list = $p_arr_function_belong_group[$i][2];
				}else{
					$v_group_list = $v_group_list . "," . $p_arr_function_belong_group[$i][2];
				}
			}else{
				if ($v_found == true){
					break;
				}
			}
		}
	}
	return $v_group_list;
}
//Ham lay thuoc tinh disabled cua chk_function_id neu chuc nang do thuoc vao cac nhom da chon:
//$v_group_list: Danh sach cac nhom ma chuc nang thuoc vao
//$arr_all_group_for_enduser: Mang chuc cac nhom cua ung dung
function get_attr_disabled_for_function($p_group_list,$p_arr_all_group_for_enduser){
	$str_return = "";
	$arr_group_list = explode(",",$p_group_list);
	for ($i=0; $i<sizeof($arr_group_list); $i++){
		for ($j=0; $j<sizeof($p_arr_all_group_for_enduser); $j++){
			// Kiem tra neu no thuoc nhom va nhom dang duoc chon cho enduser
			if (($arr_group_list[$i] == $p_arr_all_group_for_enduser[$j][0]) and ($p_arr_all_group_for_enduser[$j][2] > 0)){
				$str_return = "disabled";
				break;
			}
		}
	}
	return $str_return;
}
?>